package graph_viewer.experiment;

import java.awt.*;
import javax.swing.*;

import java.io.*;
import java.util.*;

import graph_viewer.app_exception.*;
import graph_viewer.canvas.*;
import graph_viewer.factory.*;
import graph_viewer.layout.*;
import graph_viewer.structure.*;
import graph_viewer.util.*;

public class  Remove_Cluttered_Node_Experiment{	
	public void action( Experiment_Metrics base_em,  Experiment_Metrics target_em ){
		Out.println( "\nBase_EM" );
		Out.println( base_em.toString() );

		Out.println( "\nTarget_EM" );
		Out.println( target_em.toString() );
		

		int[] orth_diff	= do_orth_comparision( base_em, target_em );
		int orth_diff_all	= orth_diff[0]  + orth_diff[1];
		
		double
			normalized_area	= target_em.find_area()/base_em.find_area(),
			normalized_L1	= target_em.find_L1_size()/base_em.find_L1_size();

		Out.println( "Expriment Result: ");
		Out.println( "\tNormalized Area,\tArea_Node Ratio,\tNormalized L1 Metrics,\tAspect Ratio,\t\tEdge Ratio,\tOrthogonal Variants");
		Out.println( "\t" + normalized_area + ",\t" + target_em.find_area_node_ratio() + ",\t" + normalized_L1 + ",\t" + target_em.find_aspect_ratio() + ",\t" + target_em.get_edge_ratio() + ",\t" + orth_diff_all );

		Out.println( "Orthogonal Result: " );		
		Out.println( "\tx_orth_diff, \ty_orth_diff ");
		Out.println( "\t" + orth_diff[0] + ", " + orth_diff[1] );
		/**/
	}

	//@return x/y_direction orth comparision
	private int[] do_orth_comparision( Experiment_Metrics base_em,  Experiment_Metrics target_em  ){
		ArrayList 
			base_x_orth_list	= base_em.get_x_orth_order(),
			base_y_orth_list	= base_em.get_y_orth_order(),
			
			compared_x_orth_list	= target_em.get_x_orth_order(),
			compared_y_orht_list	= target_em.get_y_orth_order();
	
		int 
			x_orth_diff	= compare_orthogonal_relation( base_x_orth_list, compared_x_orth_list ),
			y_orth_diff	= compare_orthogonal_relation( base_y_orth_list, compared_y_orht_list );

		return new int[]{ x_orth_diff, y_orth_diff };
	}

	private int compare_orthogonal_relation( ArrayList base_list, ArrayList target_list ){
		int orth_difference	= 0;

		int
			base_list_size			= base_list.size(),
			compared_list_size	 	= target_list.size();
		
		if (  base_list_size != compared_list_size ){			
			throw new App_Exception( "Invalid compared orthogonal list!");
		}

		for ( int i = 0 ; i < base_list_size; i++ ){
			String base_list_label		= (String)base_list.get( i );
			
			int poistion_at_compared_list	 = target_list.indexOf( base_list_label );
			
			Debug.println( base_list_label + " position ", 6 );
			Debug.println( "\tin base_list: " + i, 6 );
			Debug.println( "\tin target_list:" + poistion_at_compared_list, 6 );

			int difference	= Math.abs( i - poistion_at_compared_list );
			Debug.println( "\tdifference: \t" + difference, 6 );

			orth_difference += difference * difference;
		}

		return orth_difference;
	}

 }//:~